﻿using EAS.Common.Players;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace EAS.Content.Projectiles
{
    public class GelProjectile : ModProjectile
    {       
        private float dustInterval = 2f;
        private float rotationSpeed = 0.1f;
        public override void SetDefaults()
        {
            Projectile.width = 16;
            Projectile.height = 16;
            Projectile.friendly = true;
            Projectile.ignoreWater = true;
            Projectile.timeLeft *= 5;
            Projectile.penetrate = 1;
            Projectile.tileCollide = false;
        }
        public override void AI()
        {
            Player player = Main.player[Projectile.owner];
            AccPlayer modPlayer = player.GetModPlayer<AccPlayer>();
            if (!modPlayer.KingSlimeCrown)
            {
                Projectile.active = false;
                return;
            }
            if (player.dead)
                modPlayer.KingSlimeCrown = false;
            if (modPlayer.KingSlimeCrown)
                Projectile.timeLeft = 2;
            Vector2 vector = player.Center - Projectile.Center;
            Projectile.Center = player.Center + new Vector2(300, 0).RotatedBy(Projectile.ai[1] + Projectile.ai[0] * MathHelper.PiOver2);
            Projectile.ai[1] += 0.01f;
            Projectile.velocity.X = (vector.X > 0f) ? -0.000001f : 0f;
            for (int i = 0; i < Main.npc.Length; i++)
            {
                NPC target = Main.npc[i];
                if (target.active && !target.friendly && target.damage > 0 && Projectile.Hitbox.Intersects(target.Hitbox))
                {
                    target.AddBuff(BuffID.Slimed, 180);
                    target.AddBuff(BuffID.Slow, 180);
                    break;
                }
            }
            Dust dust = Dust.NewDustPerfect(Projectile.Center, DustID.Electric, Vector2.Zero, 0, Color.Blue, 1f);
            dust.noGravity = true;
        }
        public override bool? CanCutTiles() => false;
    }

}